package com.peihua.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.peihua.domain.Result;
import com.peihua.domain.SearchTag;
import com.peihua.service.SearchTagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/tags")
public class SearchTagController {

    @Autowired
    private SearchTagService searchTagService;

    @GetMapping("/random")
    public Result randomFive(){
        QueryWrapper<SearchTag> qw = new QueryWrapper<>();
        qw.last("ORDER BY RAND() LIMIT 5");
        List<SearchTag> list = searchTagService.list(qw);
        return Result.success(list);
    }
}